package leetcode.code1436;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import leetcode.helper.HelpDebug;

public class Solution1436_1 {

	public String destCity(List<List<String>> paths) {
		Set<String> froms = new HashSet<>();
		Set<String> tos = new HashSet<>();
		for (List<String> path : paths) {
			String from = path.get(0);
			String to = path.get(1);
			if (!froms.contains(to)) {
				tos.add(to);
			}
			froms.add(from);
			tos.remove(from);
		}
		return tos.toArray(new String[] {})[0];
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str = "[[\"London\",\"New York\"],[\"New York\",\"Lima\"],[\"Lima\",\"Sao Paulo\"]]";
		String e = "\"Sao Paulo\"";
		Solution1436_1 so = new Solution1436_1();
		String r = so.destCity(HelpDebug.str2intlist2(str));
		HelpDebug.compare(e, r);

		str = "[[\"pYyNGfBYbm\",\"wxAscRuzOl\"],[\"kzwEQHfwce\",\"pYyNGfBYbm\"]]";
		e = "\"wxAscRuzOl\"";
		r = so.destCity(HelpDebug.str2intlist2(str));
		HelpDebug.compare(e, r);

	}

}
